﻿using System.Linq;
using BSDS.Core.Model.Data;

namespace BSDS.Core.Model.Services.Geocoding
{
    public class GeocodingResult
    {
        private readonly EntityValue[] results;

        public GeocodingResult(EntityValue[] results)
        {
            this.results = results;
        }

        public bool AllEntitiesValid()
        {
            return results.All(e => !e.IsFailedEntity());
        }

        public bool AllEntitiesHighConfidence()
        {
            return results.All(e => e.IsHighConfidence());
        }

        public EntityValue[] GetSuccessfullyGeocodedEntities()
        {
            return results.Where(e => !e.IsFailedEntity()).ToArray();
        }

        public EntityValue[] GetAllEntities()
        {
            return results.ToArray();
        }

        public EntityValue[] GetFailedEntities()
        {
            return results.Where(e => e.IsFailedEntity()).ToArray();
        }

        public EntityValue[] GetImpreciseEntities()
        {
            return results.Where(e => e.IsImpreciseEntity()).ToArray();
        }

        public EntityValue[] GetImpreciseOrBadEntities()
        {
            return results.Where(e => e.IsImpreciseOrBadEntity()).ToArray();
        }

        public EntityValue[] GetNotHighConfidenceEntities()
        {
            return results.Where(e => !e.IsHighConfidence()).ToArray();
        }

        public bool ContainsEntity(string EntityID)
        {
            return results.Any(e => e.PrimaryKeyValue == EntityID);
        }
    }
}